// pages/index/index_add/index_add.js
const $api = require("../../../api/index").API
const $upload = require("../../../api/upload").API


Page({
    data: {
<<<<<<< HEAD
        fileList: [],
        circle_files:[],
        circle_content:"",
=======
        fileList: [
          {
            url: 'https://img.yzcdn.cn/vant/leaf.jpg',
            name: '图片1',
          },
          // Uploader 根据文件后缀来判断是否为图片文件
          // 如果图片 URL 中不包含类型信息，可以添加 isImage 标记来声明
          {
            url: 'http://iph.href.lu/60x60?text=default',
            name: '图片2',
            isImage: true,
            deletable: true,
          },
        ],
        circle_files:[],
        txt:"",
>>>>>>> 1c9ce1fdc7fcbf1a028b999eb3cd07f698a8a329
    },
    // 事件处理函数
    bindViewTap() {

    },
    onLoad() {
        var t = this
    },
    upload(e){
      var t = this
      console.log("upload")
      console.log(e.detail.file)
    },
    // 发布动态
    saveDynamic() {
      var t = this,
      data = {
        member_id:wx.getStorageSync('memberinfo').member_id,
        member_type:wx.getStorageSync('memberinfo').member_type,
        institution_id:wx.getStorageSync('TeacherClassinfo').institution_id,
        grade_id:wx.getStorageSync('TeacherClassinfo').grade_id,
        class_id:wx.getStorageSync('TeacherClassinfo').class_id,
        circle_content:t.data.txt,
        circle_open:"",
        circle_address:"",
        circle_longitude:"",
        circle_latitude:"",
        circle_type:"text",
        circle_files:t.data.circle_files,
      }
      $api.saveDynamic(data).then(res=>{
        console.log(res)
      })
    },
    settxt(e){
      var t = this
      t.setData({
        txt:e.detail
      })
<<<<<<< HEAD
    },
    chooseimg(e){
      var t =this
   
      console.log(e)
      var fileList = t.data.fileList
      fileList = fileList.concat(e.detail.file)
      t.setData({
        fileList:fileList
      })
      var filepath = fileList[0].url
      
     },
   
  imgdelete(e){
    console.log(e.detail.index)
    var t = this
    var fileList = t.data.fileList
    fileList.splice(e.detail.index,1)
    t.setData({
      fileList:fileList
    })
  },
  settext(e){
    var t = this
    t.setData({
      circle_content:e.detail
    })
  },
  saveDynamic(){
    var t = this
    $upload.uploadQiniu(t.data.fileList).then(res=>{

      var data = {
        member_id:wx.getStorageSync('user').member_id,
        member_type:wx.getStorageSync('user').member_type,
        institution_id:wx.getStorageSync('classinfo').institution_id,
        grade_id:wx.getStorageSync('classinfo').grade_id,
        class_id:wx.getStorageSync('classinfo').class_id,
        circle_content:t.data.circle_content,
        circle_files:res,
        circle_open:true,
        circle_address:"",
        circle_longitude:0.1,
        circle_latitude:0.1,
        circle_type:t.data.fileList[0].type 
      }
      $api.saveDynamic(data).then(res=>{
        console.log(res)
      })
    })
    
  },
  before(e){
    console.log(e.detail.file)

  },
=======
    }
>>>>>>> 1c9ce1fdc7fcbf1a028b999eb3cd07f698a8a329
})
